package cn.com.dhc.danlu.widget.couponview;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import cn.com.dhc.danlu.R;
import cn.com.dhc.danlu.widget.base.BasePopupWindow;

/**
 * @author: 李一方
 * @time: 2016-09-23 16:12
 * @mail: liyifang@danlu.com
 * @desc: 我的优惠券右上角菜单
 */
public class CouponMorePopupView extends BasePopupWindow {
    private TextView tvDesc;
    private TextView tvCoupon;
    private View.OnClickListener onMenuClickListener;

    public CouponMorePopupView(Context context, ViewGroup rootView) {
        super(context);
        init(rootView);
    }

    private void init(ViewGroup rootView) {
        Context context = rootView.getContext();
        View popView = LayoutInflater.from(context).inflate(R.layout.popview_coupon_more, rootView, false);
        popView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        setFocusable(true);
        initChildView(popView);
        setContentView(popView);
    }

    private void initChildView(View popView) {
        tvDesc = (TextView) popView.findViewById(R.id.tv_desc);
        tvCoupon = (TextView) popView.findViewById(R.id.tv_coupon);

        tvDesc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onMenuClickListener.onClick(v);
            }
        });
        tvCoupon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onMenuClickListener.onClick(v);
            }
        });
    }

    public void setMenuItem(int resIdOne, int resIdTwo) {
        tvCoupon.setText(resIdOne);
        tvDesc.setText(resIdTwo);
    }

    public void setMenuItem(String resOne, String resTwo) {
        if (!TextUtils.isEmpty(resOne)) {
            tvCoupon.setText(resOne);
        }
        if (!TextUtils.isEmpty(resTwo)) {
            tvDesc.setText(resTwo);
        }
    }

    public void setOnMenuClickListener(View.OnClickListener onMenuClickListener) {
        this.onMenuClickListener = onMenuClickListener;
    }
}